from visual import * from __future__ import division # makes 1/2 be 0.5, not 0 #right button mouse drag spins (Mac: option key + mouse) #double button mouse drag zooms (Mac: command key + mouse) #--------------------------------------------------------- # This stuff makes labeled coordinate axes d=1.5 #adjust length of axes as needed r=0.01 #adjust thickness of axes as needed scene.background=color.white scene.x=scene.y=0 scene.width=scene.height=800 xaxis=cylinder(pos=(0,0,0),axis=(d,0,0),radius=r) yaxis=cylinder(pos=(0,0,0),axis=(0,d,0),radius=r) zaxis=cylinder(pos=(0,0,0),axis=(0,0,d),radius=r) label(pos=xaxis.pos+xaxis.axis,text='x',box=0) label(pos=yaxis.pos+yaxis.axis,text='y',box=0) label(pos=zaxis.pos+zaxis.axis,text='z',box=0) #--------------------------------------------------------- scene.autoscale=0 # don't adjust view when ball is near edge of window ## constants g = 9.8 deltat = 0.01 L0 = ??? # unstretched length of spring ks = ??? #you may want to model a spring from your table ## create objects ball = sphere(pos = vector(???,???,???), radius = 0.1, color = color.blue) # place ball ball.m = ??? spring = helix(pos = ???, axis = ???, coils = 15, thickness = 0.01, radius = 0.05, color = color.orange) # place one end of the spring on the Y-axis and the other end at the ball ## initial values ball.p = ball.m*vector(0,0,0) #initial momentum of ball ## calculation loop while True: # repeat forever. rate(100) # this slows things down a bit #You may need information about the length, direction, etc. of spring here. Fgrav = ?? # use gravitational force law Fspring = ?? # use force law for springs (in general: 3 dimensions!) Fnet = ?? #sum the forces ? # update the momentum of the ball ? # update the position of the ball ? # after updating the ball, you'll need to update the spring!